package routers

import (
	"blog/api/v1"
	"blog/middleware"
	"blog/utils"
	"github.com/gin-gonic/gin"
)

func InitRouter(){
	gin.SetMode(utils.AppMode)
	r := gin.New()
	r.Use(gin.Recovery())
	r.Use(middleware.LoggerMiddleware())
	r.Use(middleware.Cors())
	r.LoadHTMLGlob("views/*")
	r.GET("",v1.Index)
	//token verify api
	auth := r.Group("api/v1",middleware.TokenVerifyMiddleware())
	{
		auth.PUT("user/:id",v1.UpdateUser)
		auth.DELETE("user/:id",v1.DeleteUser)

		auth.POST("category",v1.AddCategory)
		auth.PUT("category",v1.UpdateCategory)
		auth.DELETE("category/:id",v1.DeleteCategory)

		auth.POST("article",v1.AddArt)
		auth.PUT("article",v1.UpdateArt)
		auth.DELETE("article",v1.DeleteArt)

		auth.POST("upload",v1.Upload)
	}
	//no token verify api
	routerV1 := r.Group("api/v1")
	{
		routerV1.POST("login",v1.Login)

		routerV1.POST("user",v1.AddUser)
		routerV1.GET("user/:id",v1.GetUser)
		routerV1.GET("users",v1.GetUsers)

		routerV1.GET("category",v1.GetCategory)
		routerV1.GET("categorys",v1.GetCategorys)

		routerV1.GET("article/:id",v1.GetArt)
		routerV1.GET("articles",v1.GetArts)
		routerV1.GET("articles/list",v1.GetArtsByCateId)
	}

	r.Run(":"+ utils.HttpPort)
}
